<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use DB;
use Illuminate\Support\Facades\Auth;

class LoginController extends Controller
{
    public function login(Request $request){
        if(is_post()){
            $input = $request->input();
            $name = DB::table("admins")->where("name",$input['name'])->first();
            if(!$name){
                return ["Status"=>"Erro","Erro"=>"账号名或密码或验证码有误"];
            }
            if (Auth::guard('admins')->attempt(['name' => $input['name'], 'password' => $input['pwd']])) {
                // 认证通过...
                return ["Status"=>"ok","Text"=>"登陆成功<br /><br />欢迎回来"];
            }else{
                return ["Status"=>"Erro","Erro"=>"账号名或密码或验证码有误"];
            }
        }else{
            return view("admin.login");
        }
    }
    public function logout(){
        Auth::guard('admins')->logout();
        return redirect()->intended('admin/login');
    }
}
